@extends('admin.app')
@section('content')
    <link rel="stylesheet" href="/css/icon/iconfont-0130.css">
    <link rel="stylesheet" href="/addons/icheck-1.x/skins/square/green.css">
    <link rel="stylesheet" href="/css/admin/mobileSelect.css">
    @if($skinid == 3)
        <link rel="stylesheet" href="{{assethelp('/css/admin/performance-setting.css?v='.time())}}">
    @elseif($skinid == 1)
        <link rel="stylesheet" href="{{assethelp('/css/theme-blue/admin/performance-setting.css?v='.time())}}">
        {{--蓝色创建新项目功能样式--}}
        <link rel="stylesheet" href="{{assethelp('/css/theme-blue/admin/create-new-project.css?v='.time())}}">
    @elseif($skinid == 2)
        <link rel="stylesheet" href="/css/theme-pink/system/iconfont-pink.css">
        <link rel="stylesheet" href="{{assethelp('/css/theme-pink/admin/performance-setting.css?v='.time())}}">
        {{--粉色创建新项目功能--}}
        <link rel="stylesheet" href="{{assethelp('/css/theme-pink/admin/create-new-project.css?v='.time())}}">
    @endif
    <script src="/addons/icheck-1.x/icheck.min.js"></script>
    <div class="mian-container">
        <div class="performance-setting">
            <div>
                <div class="weui-cell top-tab">
                    <div class="weui-cell__hd go-back">
                        <p style="/* width: 15px */"></p>
                    </div>
                    <div class="weui-cell__bd centertxt">
                        销售业绩设置
                    </div>
                    <div class="weui-cell__ft"></div>
                </div>
            </div>
            <div class="weui-cells choose-time">
                <div class="weui-cell">
                    <div class="weui-cell__hd">
                        <p><i class="icon iconfont icon-kaoqin"></i>选择时间</p>
                    </div>
                    <div class="weui-cell__bd">
                        <div id="trigger3">{{$year}}-{{$month}}</div>
                    </div>
                </div>
                <div class="weui-cell" onclick="window.location.href='{{url('/admin/cost/standard?year='.$year.'&month='.$month)}}'">
                    <div class="weui-cell__hd">
                        <p class="scale"><img src="/img/scale.png"/></p>
                    </div>
                    <div class="weui-cell__bd">
                        <p>标准比例</p>
                    </div>
                    <div class="weui-cell__ft scale-arrow">
                        <a id="trigger4"></a>
                    </div>
                </div>
            </div>
            <div class="center-list">
                @foreach($tongxunlu as $t)
                    <div class="section-list">
                        <h3 class="h3-title">
                            @if($t['group_name'] != '我的同事')
                                <img class="con-img" src="{{asset('/img/list-user1.png')}}">
                            @endif{{$t['group_name']}}
                        </h3>

                        <span class="num-span"></span>
                        <ul>
                            @foreach($t['member'] as $m)
                                <li>

                                    <img class="sec-img" src="{{userlogo($m['id'])}}">
                                    <span class="sec-name">{{$m['qw_name']}}</span>
                                    @foreach($m->role as $mr)
                                        <span  class="circle-span @if($mr==9) span-total @elseif($mr==10) span-exam @elseif($mr==11) span-score @elseif($mr==12) span-reward @endif">{{$roleArray[$mr]}}</span>
                                    @endforeach
                                    @if($m['is_sales'] == 1)
                                        <span class="circle-span span-sell">销</span>
                                    @endif

                                    <div class="hidden-div" style="font-family:'黑体'">
                                        <div class="weui-flex">
                                            <div class="weui-flex__item create-item">
                                                <i class="icon iconfont icon-addition"></i>创建项目
                                            </div>
                                        </div>
                                        <input type="hidden" value="{{$m->id}}" class="user_id">

                                        <div class="new_container">
                                            <div class="new_tit">
                                                <input type="text" name="title" value="{{isset($m->month->name)?$m->month->name:''}}" placeholder="请填写项目名称" class="admin_name"  onfocus="this.placeholder=''">
                                            </div>
                                            <div class="new_texta_con">
                                                <div class="new_texta">
                                                    <textarea name="detail" class="textar_txt">{{isset($m->month->description)?$m->month->description:''}}</textarea>
                                                    <div>
                                                        <div class="area-btn month-save-btn">确定</div>
                                                    </div>
                                                </div>
                                                @foreach($m->month_detail as $mmd)
                                                    <div class="new_con">
                                                        <div class="new_con1">
                                                            <div class="new_con1_tit">费用</div>
                                                            <div class="new_con1_inp">
                                                                <input type="text" name="cost" value="{{$mmd->score}}" class="admin_free">
                                                            </div>
                                                        </div>
                                                        <div class="new_con2">
                                                            <div>
                                                                <div class="new_con2_sure" data-id="{{$mmd->id}}">确定</div>
                                                            </div>
                                                            <div>
                                                                <div class="new_con2_del" data-id="{{$mmd->id}}">删除</div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                @endforeach
                                            </div>
                                        </div>
                                    </div>
                                </li>
                            @endforeach
                        </ul>
                        @if(isset($t['child']))
                            @foreach($t['child'] as $c)
                                <div class="second-list">
                                    <h3 class="h3-title">
                                        <img class="con-img" src="{{asset('/img/list-user1.png')}}">{{$c['group_name']}}
                                    </h3>
                                    <span class="num-span"></span>
                                    <ul>
                                        @foreach($c['member'] as $cm)
                                            <li>
                                                <img class="sec-img" src="{{userlogo($cm['id'])}}">
                                                <span class="sec-name">{{$cm['qw_name']}}</span>
                                                @if($cm['is_leader'] == 1)<i class="icon iconfont icon-qizi"></i>@endif
                                                @foreach($cm->role as $cmr)

                                                    <span  class="circle-span @if($cmr==9) span-total @elseif($cmr==10) span-exam @elseif($cmr==11) span-score @elseif($cmr==12) span-reward @endif">{{$roleArray[$cmr]}}</span>
                                                @endforeach
                                                @if($cm['is_sales'] == 1)
                                                    <span class="circle-span span-sell">销</span>
                                                @endif
                                                {{--<div class="hidden-div" style="font-family:'黑体'">--}}
                                                    {{--<div class="weui-flex">--}}
                                                        {{--<div class="weui-flex__item create-item">--}}
                                                            {{--<i class="icon iconfont icon-addition"></i>创建项目--}}
                                                        {{--</div>--}}
                                                    {{--</div>--}}
                                                    {{--<input type="hidden" value="" class="user_id">--}}
                                                {{--</div>--}}

                                                <div class="hidden-div" style="font-family:'黑体'">
                                                    <div class="weui-flex">
                                                        <div class="weui-flex__item create-item">
                                                            <i class="icon iconfont icon-addition"></i>创建项目
                                                        </div>
                                                    </div>
                                                    <input type="hidden" value="{{$cm->id}}" class="user_id">

                                                    <div class="new_container">
                                                        <div class="new_tit">
                                                            <input type="text" name="title" value="{{isset($cm->month->name)?$cm->month->name:''}}" placeholder="请填写项目名称" class="admin_name"  onfocus="this.placeholder=''">
                                                        </div>
                                                        <div class="new_texta_con">
                                                            <div class="new_texta">
                                                                <textarea name="detail" class="textar_txt">{{isset($cm->month->description)?$cm->month->description:''}}</textarea>
                                                                <div>
                                                                    <div class="area-btn month-save-btn">确定</div>
                                                                </div>
                                                            </div>
                                                            @foreach($cm->month_detail as $mmd)
                                                                <div class="new_con">
                                                                    <div class="new_con1">
                                                                        <div class="new_con1_tit">费用</div>
                                                                        <div class="new_con1_inp">
                                                                            <input type="text" name="cost" value="{{$mmd->score}}" class="admin_free">
                                                                        </div>
                                                                    </div>
                                                                    <div class="new_con2">
                                                                        <div>
                                                                            <div class="new_con2_sure" data-id="{{$mmd->id}}">确定</div>
                                                                        </div>
                                                                        <div>
                                                                            <div class="new_con2_del" data-id="{{$mmd->id}}">删除</div>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            @endforeach
                                                        </div>
                                                    </div>
                                                </div>
                                            </li>
                                        @endforeach
                                    </ul>
                                    @foreach($c['child'] as $cc)
                                        <div class="third-list">
                                            <h3 class="h3-title">
                                                <img class="con-img" src="{{asset('/img/list-user1.png')}}">{{$cc['group_name']}}
                                            </h3>
                                            <span class="num-span"></span>
                                            <ul>
                                                @foreach($cc['member'] as $ccm)
                                                    <li>

                                                        <img class="sec-img" src="{{userlogo($ccm['id'])}}">
                                                        <span class="sec-name">{{$ccm['qw_name']}}</span>
                                                        @if($ccm['is_leader'] == 1)
                                                            <i class="icon iconfont icon-qizi"></i>@endif
                                                        @foreach($ccm->role as $ccmr)
                                                            <span  class="circle-span @if($ccmr==9) span-total @elseif($ccmr==10) span-exam @elseif($ccmr==11) span-score @elseif($ccmr==12) span-reward @endif">{{$roleArray[$ccmr]}}</span>
                                                        @endforeach
                                                        @if($ccm['is_sales'] == 1)
                                                            <span class="circle-span span-sell">销</span>
                                                        @endif
                                                        {{--<div class="hidden-div" style="font-family:'黑体'">--}}
                                                            {{--<div class="weui-flex">--}}
                                                                {{--<div class="weui-flex__item create-item">--}}
                                                                    {{--<i class="icon iconfont icon-addition"></i>创建项目--}}
                                                                {{--</div>--}}
                                                            {{--</div>--}}
                                                            {{--<input type="hidden" value="" class="user_id">--}}
                                                        {{--</div>--}}

                                                        <div class="hidden-div" style="font-family:'黑体'">
                                                            <div class="weui-flex">
                                                                <div class="weui-flex__item create-item">
                                                                    <i class="icon iconfont icon-addition"></i>创建项目
                                                                </div>
                                                            </div>
                                                            <input type="hidden" value="{{$ccm->id}}" class="user_id">

                                                            <div class="new_container">
                                                                {{--<div class="new_tit">
                                                                    <input type="text" name="title" value="{{isset($ccm->month->name)?$ccm->month->name:''}}" placeholder="请填写项目名称" class="admin_name"  onfocus="this.placeholder=''">
                                                                </div>--}}
                                                                <div class="new_texta_con">
                                                                    <div class="new_texta">
                                                                        <textarea name="detail" class="textar_txt" placeholder="备注"   onfocus="this.placeholder=''">{{isset($ccm->month->description)?$ccm->month->description:''}}</textarea>
                                                                        <div>
                                                                            <div class="area-btn month-save-btn">确定</div>
                                                                        </div>
                                                                    </div>
                                                                    @foreach($ccm->month_detail as $mmd)
                                                                        <div class="new_con">
                                                                            <div class="new_con1">
                                                                                <div class="new_con1_tit">费用</div>
                                                                                <div class="new_con1_inp">
                                                                                    <input type="text" name="cost" value="{{$mmd->score}}" class="admin_free">
                                                                                </div>
                                                                            </div>
                                                                            <div class="new_con2">
                                                                                <div>
                                                                                    <div class="new_con2_sure" data-id="{{$mmd->id}}">确定</div>
                                                                                </div>
                                                                                <div>
                                                                                    <div class="new_con2_del" data-id="{{$mmd->id}}">删除</div>
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                    @endforeach
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </li>
                                                @endforeach
                                            </ul>
                                        </div>
                                    @endforeach
                                </div>
                            @endforeach
                        @endif
                    </div>
                @endforeach

            </div>
        </div>
        {!! csrf_field() !!}

        @if($user->getRole()==9)
            @include('sysadmin.admin-caidan')
        @else
            <div class="reful-tabbar">
                <a href="{{url('/user/performance/perf')}}" class="tabbar-item">
                    <p style="line-height: 65px;" class="tabbar-label">返回个人用户界面</p>
                </a>
            </div>

        @endif
    </div>

    <script src="/js/mobileSelect.js"></script>
    <script>
        $(document).ready(function () {
            var time = '{{$start}}';
            var token = $('input[name=_token]').val();
            var UplinkData = [
                {
                    id: '2017',
                    value: '2017年',
                    childs: [
                        {id: '1', value: '1月'},
                        {id: '2', value: '2月'},
                        {id: '3', value: '3月'},
                        {id: '4', value: '4月'},
                        {id: '5', value: '5月'},
                        {id: '6', value: '6月'},
                        {id: '7', value: '7月'},
                        {id: '8', value: '8月'},
                        {id: '9', value: '9月'},
                        {id: '10', value: '10月'},
                        {id: '11', value: '11月'},
                        {id: '12', value: '12月'}
                    ]
                },
                {
                    id: '2018',
                    value: '2018年',
                    childs: [
                        {id: '1', value: '1月'},
                        {id: '2', value: '2月'},
                        {id: '3', value: '3月'},
                        {id: '4', value: '4月'},
                        {id: '5', value: '5月'},
                        {id: '6', value: '6月'},
                        {id: '7', value: '7月'},
                        {id: '8', value: '8月'},
                        {id: '9', value: '9月'},
                        {id: '10', value: '10月'},
                        {id: '11', value: '11月'},
                        {id: '12', value: '12月'}
                    ]
                },
                {
                    id: '2019',
                    value: '2019年',
                    childs: [
                        {id: '1', value: '1月'},
                        {id: '2', value: '2月'},
                        {id: '3', value: '3月'},
                        {id: '4', value: '4月'},
                        {id: '5', value: '5月'},
                        {id: '6', value: '6月'},
                        {id: '7', value: '7月'},
                        {id: '8', value: '8月'},
                        {id: '9', value: '9月'},
                        {id: '10', value: '10月'},
                        {id: '11', value: '11月'},
                        {id: '12', value: '12月'}
                    ]
                },
                {
                    id: '2020',
                    value: '2020年',
                    childs: [
                        {id: '1', value: '1月'},
                        {id: '2', value: '2月'},
                        {id: '3', value: '3月'},
                        {id: '4', value: '4月'},
                        {id: '5', value: '5月'},
                        {id: '6', value: '6月'},
                        {id: '7', value: '7月'},
                        {id: '8', value: '8月'},
                        {id: '9', value: '9月'},
                        {id: '10', value: '10月'},
                        {id: '11', value: '11月'},
                        {id: '12', value: '12月'}
                    ]
                },
                {
                    id: '2021',
                    value: '2021年',
                    childs: [
                        {id: '1', value: '1月'},
                        {id: '2', value: '2月'},
                        {id: '3', value: '3月'},
                        {id: '4', value: '4月'},
                        {id: '5', value: '5月'},
                        {id: '6', value: '6月'},
                        {id: '7', value: '7月'},
                        {id: '8', value: '8月'},
                        {id: '9', value: '9月'},
                        {id: '10', value: '10月'},
                        {id: '11', value: '11月'},
                        {id: '12', value: '12月'}
                    ]
                },
                {
                    id: '2022',
                    value: '2022年',
                    childs: [
                        {id: '1', value: '1月'},
                        {id: '2', value: '2月'},
                        {id: '3', value: '3月'},
                        {id: '4', value: '4月'},
                        {id: '5', value: '5月'},
                        {id: '6', value: '6月'},
                        {id: '7', value: '7月'},
                        {id: '8', value: '8月'},
                        {id: '9', value: '9月'},
                        {id: '10', value: '10月'},
                        {id: '11', value: '11月'},
                        {id: '12', value: '12月'}
                    ]
                },
                {
                    id: '2023',
                    value: '2023年',
                    childs: [
                        {id: '1', value: '1月'},
                        {id: '2', value: '2月'},
                        {id: '3', value: '3月'},
                        {id: '4', value: '4月'},
                        {id: '5', value: '5月'},
                        {id: '6', value: '6月'},
                        {id: '7', value: '7月'},
                        {id: '8', value: '8月'},
                        {id: '9', value: '9月'},
                        {id: '10', value: '10月'},
                        {id: '11', value: '11月'},
                        {id: '12', value: '12月'}
                    ]
                },
                {
                    id: '2024',
                    value: '2024年',
                    childs: [
                        {id: '1', value: '1月'},
                        {id: '2', value: '2月'},
                        {id: '3', value: '3月'},
                        {id: '4', value: '4月'},
                        {id: '5', value: '5月'},
                        {id: '6', value: '6月'},
                        {id: '7', value: '7月'},
                        {id: '8', value: '8月'},
                        {id: '9', value: '9月'},
                        {id: '10', value: '10月'},
                        {id: '11', value: '11月'},
                        {id: '12', value: '12月'}
                    ]
                },
                {
                    id: '2025',
                    value: '2025年',
                    childs: [
                        {id: '1', value: '1月'},
                        {id: '2', value: '2月'},
                        {id: '3', value: '3月'},
                        {id: '4', value: '4月'},
                        {id: '5', value: '5月'},
                        {id: '6', value: '6月'},
                        {id: '7', value: '7月'},
                        {id: '8', value: '8月'},
                        {id: '9', value: '9月'},
                        {id: '10', value: '10月'},
                        {id: '11', value: '11月'},
                        {id: '12', value: '12月'}
                    ]
                },
            ]
            var mobileSelect3 = new MobileSelect({
                trigger: '#trigger3',
                title: '选择时间',
                wheels: [
                    {data: UplinkData}
                ],
                //     keyMap: {
                //        id:'id',
                //        value: 'name',
                //        childs :'son'
                //      },
                position: [0, 1],
                callback: function (indexArr, data) {
                    //
                    var year = data[0].id;
                    var month = data[1].id;

                    window.location.href = '/admin/cost?year=' + year + '&month=' + month;
                    console.log(data[1].id); //返回选中的json数据
                }
            });

            $('body').on('focus', '.score', function () {
                $(this).parent().next('.sure').toggleClass('sure');
            });


            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $('input').iCheck({
                labelHover: false,
                cursor: true,
                checkboxClass: 'icheckbox_square-blue',  // 注意square和blue的对应关系
                radioClass: 'iradio_square-blue',
                increaseArea: '20%' // optional
            });
            $('.num-span').each(function () {
                $(this).text($(this).next('ul').children().length);
            });
            $('.h3-title').click(function () {
                $(this).toggleClass('ah3-title');
                $(this).siblings('ul').toggle();
            });
            $('.h3-title').click();
            $('.kaohe-item').click(function () {
                $('.show-hidden').toggle();
            });
            $('.admin-item').click(function () {
                $('.front-show-hidden').toggle();
            });
            $('.delete-item').click(function () {
                $(this).parent().siblings().find('.icon-shanchu3').toggle();
            })

            $('.sec-name').click(function () {
                $(this).toggleClass('sec-after');
                $(this).siblings('.hidden-div').toggle();

            })
            //删除，ajax
            $('body').on('click', '.button-shanchu3', function () {
                var that = this;
                $.confirm({
                    title: '删除',
                    text: '删除该项目和项目下分值',
                    onOK: function () {     //删除
                        //ajax
                        var dataId = $(that).parent().parent().attr('data-id');
                        if (dataId) {
                            ajax_achievement_delete($(that).parent().parent().attr('data-id'));
                            $(that).parent().parent().remove();
                            //  $(that).parent().parent().siblings().find('.icon-shanchu3').toggle();
                        } else {
                            $(that).parent().parent().remove();
                        }

                    },
                    onCancel: function () {


                    }
                });
            })

            // 返回上一页
            $('.go-back').click(function(){
                localStorage.setItem('eee',Date.now());
                window.history.back(-1);
                //history.go(-1);
                // window.location.href=document.referrer;
            });


            //保存月度的标题和描述
            $("body").on('click', '.month-save-btn', function () {
                var that = this;
                var title = $(this).parent().parent().parent().parent().find('input[name=title]').val();
                var detail = $(this).parent().parent().parent().parent().find('textarea[name=detail]').val();
                var user_id = $(this).parent().parent().parent().parent().parent().find(".user_id").val();
                console.log(title,detail,user_id);
                console.log(time);
                $.ajax({
                    type: 'post',
                    cache: 'false',
                    url: '/admin/cost/monthsave',
                    data: 'title=' + title +  '&time=' + time + '&detail=' + detail + '&_token=' + token + '&user_id=' + user_id,
                    dataType: 'json',
                    heads : {
                        'content-type' : 'application/x-www-form-urlencoded'
                    },
                    success: function (data) {
                        if (data.status == 'success') {
                            $.toast(data.msg, 'text');
                        } else {
                            $.toast(data.msg, 'text');
                            /*setTimeout(function () {
                             $(that).parent().parent().parent().remove();
                             }, 300);*/
                        }
                    },
                    error: function () {
                        $.toptip('网络异常请重试', 'warning');
                    }
                });
            });




            // 创建项目
            $('.create-item').click(function () {
                $(this).parent().siblings('.new_container').find('.new_texta_con').append('<div class="new_con">'
                        +'<div class="new_con1">'
                        +'<div class="new_con1_tit">费用</div>'
                        +'<div class="new_con1_inp">'
                        +'<input type="text" name="cost" value="" class="admin_free">'
                        +'</div>'
                        +'</div>'
                        +'<div class="new_con2">'
                        +'<div>'
                        +'<div class="new_con2_sure" data-id="0">确定</div>'
                        +'</div>'
                        +'<div>'
                        +'<div class="new_con2_del" data-id="0">删除</div>'
                        +'</div>'
                        +'</div>'
                        +'</div>');
            })

            //创建项目-点击删除
            $('body').on("click", '.new_con2_del', function () {
                var did = $(this).attr('data-id');
                if(did == 0){
                    $(this).parents('.new_con2').siblings('.new_con1').parents('.new_con').remove()
                    return;
                }
                var that = this;
                $.ajax({
                    type: 'post',
                    cache: 'false',
                    url: '/admin/cost/month-detail-delete',
                    data: 'cost=' + 1 +  '&time=' + time + '&id=' + did,
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 'success') {
                            $.toast(data.msg, 'text');
                            $(that).parents('.new_con2').siblings('.new_con1').parents('.new_con').remove()
                        } else {
                            $.toast(data.msg, 'text');
                        }
                    },
                    error: function () {
                        $.toptip('网络异常请重试', 'warning');
                    }
                });

            });


            //创建项目-点击确认
            $('body').on("click", '.new_con2_sure', function () {
                var that = this;
                var cost = $(this).parent().parent().parent().find('input[name=cost]').val();
                var did = $(this).attr('data-id');
                var user_id = $(this).parent().parent().parent().parent().parent().parent().find(".user_id").val();
                console.log(user_id);
                console.log(cost);
                $.ajax({
                    type: 'post',
                    cache: 'false',
                    url: '/admin/cost/month-detail-save',
                    data: 'cost=' + cost +  '&time=' + time + '&id=' + did + '&user_id=' + user_id,
                    dataType: 'json',
                    heads : {
                        'content-type' : 'application/x-www-form-urlencoded'
                    },
                    success: function (data) {
                        if (data.status == 'success') {
                            $.toast(data.msg, 'text');
                            $(that).attr('data-id',data.data);
                            $(that).parent().parent().parent().find('.new_con2_del').attr('data-id',data.data);
                        } else {
                            $.toast(data.msg, 'text');
                            /*setTimeout(function () {
                                $(that).parent().parent().parent().remove();
                            }, 300);*/
                        }
                    },
                    error: function () {
                        $.toptip('网络异常请重试', 'warning');
                    }
                });
            });

            //确定，提交信息取input信息，ajax
            $('body').on('click', '.button-queding', function () {
                $(this).parent();
                var name = $(this).parent().parent().find('.name').html();
                var standard = $(this).parent().parent().find('.standard').val();
                var score = $(this).parent().parent().find('.score').val();
                var id = $(this).parent().parent().attr('data-id');
                var user_id = $(this).parent().parent().parent().find(".user_id").val();
                var tip = $(this).parent().parent().find(".title-na").attr("id");

                if (id) {
                    ajax_achievement_update(score, standard, user_id, id, $(this).parent().parent())
                } else {
                    ajax_achievement_create(name, standard, score, user_id, $(this).parent().parent(),tip);
                }
            });
            $('.hidden-sec .popup i').click(function () {
                $('.hidden-sec').css('display', 'none');
                $('.shadow-hidden').css('display', 'none');
            })
            function ajax_achievement_create(name, standard, score, user_id, dom,tip) {
                var url = '/admin/achievement';
                $.ajax({
                    type: 'post',
                    cache: 'false',
                    url: url,
                    data: 'name=' + name + '&standard=' + standard + '&score=' + score + '&user_id=' + user_id + '&time=' + time + '&tip=' + tip,
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 'success') {
                            $.toptip(data.msg, 'success');
                            console.log(dom);
                            dom.attr('data-id', data.data.id);
                            dom.find('i').toggleClass('sure');
                            setTimeout(function () {
                                dom.find('i').removeClass("sure");
                            }, 3000);
                        } else {
                            $.toptip(data.msg, 'error');
                            setTimeout(function () {
                                window.location.href = data.redirectUrl;
                            }, 1000);
                        }
                    },
                    error: function () {
                        $.toptip('网络异常请重试', 'warning');
                    }
                });
            }

            function ajax_achievement_update(score,standard, user_id, id, dom) {
                var url = '/admin/achievement/' + id;
                $.ajax({
                    type: 'put',
                    cache: 'false',
                    url: url,
                    data: 'id=' + id + '&score=' + score + '&user_id=' + user_id + '&standard=' + standard,
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 'success') {
                            $.toptip(data.msg, 'success');
                            dom.find('i').toggleClass('sure');
                            setTimeout(function () {
                                dom.find('i').removeClass("sure");
                            }, 3000);
                        } else {
                            $.toptip(data.msg, 'error');
                            setTimeout(function () {
                                window.location.href = data.redirectUrl;
                            }, 1000);
//                            window.location.href= data.redirectUrl;
                        }
                    },
                    error: function () {
                        $.toptip('网络异常请重试', 'warning');
                    }
                });
            }

            function ajax_achievement_delete(id) {
                var url = '/admin/achievement/' + id;
                $.ajax({
                    type: 'delete',
                    cache: 'false',
                    url: url,
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 'success') {
                            $.toptip(data.msg, 'success');
                        } else {
                            $.toptip(data.msg, 'error');
                            setTimeout(function () {
                                window.location.href = data.redirectUrl;
                            }, 1000);
//                            window.location.href= data.redirectUrl;
                        }
                    },
                    error: function () {
                        $.toptip('网络异常请重试', 'warning');
                    }
                });
            }
        })
    </script>
@endsection
